package com.os.meituan.common;

import com.os.meituan.common.PubClass;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import javax.annotation.Resource;
import java.io.Serializable;

public class IdWorkerGenerator implements IdentifierGenerator {
    @Resource
    private PubClass pubClass;

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        try {
            return String.valueOf(MyIdWorker.nextId());

        } catch (Exception e) {
            pubClass.showErrorLog(e.getMessage(), IdWorkerGenerator.class);
            throw new HibernateException(
                    "无法读取IdWorker生成的新Id");
        }
    }
}
